package com.cloudsigns.factorymanager2.project.presenter;

import com.cloudsigns.factorymanager2.engineering.model.AddCompletionOrderCommentModel;
import com.cloudsigns.factorymanager2.project.iview.IAddEngineeringSurveyOrderView;
import com.cloudsigns.factorymanager2.project.model.AddEngineeringSurveyOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddEngineeringSurveyOrderModel;

/**
 * Created by tony on 2018/8/5.
 */

public class AddEngineeringSurveyOrderPresenter {
    private IAddEngineeringSurveyOrderView view;
    private IAddEngineeringSurveyOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public AddEngineeringSurveyOrderPresenter(IAddEngineeringSurveyOrderView view) {
        this.view = view;
        this.model = new AddEngineeringSurveyOrderModel();
    }

    public void addEngineeringSurveyOrder() {

        model.addEngineeringSurveyOrder(view.getCompleteDate(), view.getContacts(), view.getContactsPhone(), view.getEngineeringAddress(), view.getEngineeringName(), view.getLat(), view.getLon(),view.getProjectName(),
                new AddEngineeringSurveyOrderModel.OnAddEngineeringSurveyOrderListener() {
            @Override
            public void addEngineeringSurveyOrderSuccessed(final String id) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addCompletionOrderCommentSuccessed(id);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void addEngineeringSurveyOrderFailed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addCompletionOrderCommentFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }

}
